package com.pig4cloud.pig.page.controller;

import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.order.api.dto.TrOrder;
import com.pig4cloud.pig.page.entity.PageQueryParam;
import com.pig4cloud.pig.page.service.PageService;
import com.pig4cloud.pig.page.vo.TrCustomer;
import com.pig4cloud.pig.page.vo.TrInquire;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/page")
@RequiredArgsConstructor
@Tag(description = "page",name="首页页面")
public class PageController {
	private final PageService pageService;
	/**
	 * 统一获取首页所有统计数据
	 */
	@GetMapping("/allData")
	public R<Map<String, Object>> getAllPageData(PageQueryParam param) {
		// 创建Map存储所有结果
		Map<String, Object> resultMap = new HashMap<>(5);
//		订单状态
		List<TrOrder> orderStatusList = pageService.selectPageStatus(param.getTrOrder());
		resultMap.put("orderStatusList", orderStatusList);
//		折线图 咨询数量
		List<TrInquire> inquiriesList = pageService.selectInquiriesNumber(param.getTrInquire());
		resultMap.put("inquiriesList", inquiriesList);
//		饼状图 客户来源
		List<TrCustomer> customerList = pageService.selectCustomer(param.getTrCustomer());
		resultMap.put("customerList", customerList);
//		饼状图 定制师完成订单占比
		List<TrOrder> completedDesignedList = pageService.selectCompletedDesigned(param.getTrOrder());
		resultMap.put("completedDesignedList", completedDesignedList);
//		柱状图，近12月订单数量
		List<TrOrder> orderNumbersList = pageService.selectOrderNumbers(param.getTrOrder());
		resultMap.put("orderNumbersList", orderNumbersList);

		return R.ok(resultMap);
	}

}
